# -!- coding: utf-8 -!-
# @FileName  :utils.py
# @Time      :2020/10/25 14:59
# @Author    :zhoujirong
# @Desc      : 企业异步查询报告主流程

import datetime
from common.log import Log
from biz.flow.ent_asyn_check import EntAsynCheckRequest
from biz.cases.base_case import BaseCase
from common.utils import get_redis


class TestEntAsynCheck(BaseCase):
    '''企业异步查询报告主流程测试用例'''

    data_file_name = 'ent_asyn_report.yaml'

    @classmethod
    def setUpClass(cls):
        cls.redis = get_redis()
        # cls.mysql = get_mysql()
        cls.cookie = BaseCase().get_token_asyn()

    def ent_receive_task_getpage(self):
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_enterpriseName = self.file_data.get('search_EQ_enterpriseName')
        search_EQ_uniformSocialCredCode = self.file_data.get('search_EQ_uniformSocialCredCode')
        search_EQ_signCode = self.file_data.get('search_EQ_signCode')
        search_EQ_orgInstCode = self.file_data.get('search_EQ_orgInstCode')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_oentator = self.file_data.get('search_EQ_oentator')
        search_EQ_oentOrg = self.file_data.get('search_EQ_oentOrg')
        search_GTE_LTE_oentTime_DATE_RANGE = self.file_data.get('search_GTE_LTE_oentTime_DATE_RANGE')
        search_EQ_oentOrgRange = self.file_data.get('search_EQ_oentOrgRange')
        search_EQ_queryFormat = self.file_data.get('search_EQ_queryFormat')
        ret = EntAsynCheckRequest.ent_receive_task_getpage(curPage,
                                                            maxSize,
                                                           search_EQ_signCode,
                                                           search_EQ_uniformSocialCredCode,
                                                           search_EQ_orgInstCode,
                                                            search_EQ_enterpriseName,
                                                            search_EQ_qryReason,
                                                            search_EQ_status,
                                                            search_EQ_oentator,
                                                            search_EQ_oentOrg,
                                                            search_GTE_LTE_oentTime_DATE_RANGE,
                                                            search_EQ_oentOrgRange,
                                                            search_EQ_queryFormat,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list

    def get_id(self):
        id_list = []
        datas = self.ent_receive_task_getpage()
        for data in datas:
            id_list.append(data.id)
        Log.info(id_list)
        return id_list

    def test_aent_checkinfo_receivetask(self):
        '''企业异步领取任务'''
        ids = self.get_id()
        ids = ','.join(ids)
        Log.info(ids)
        ret = EntAsynCheckRequest.ent_checkinfo_receivetask(ids,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)

    def get_page(self):
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_enterpriseName = self.file_data.get('search_EQ_enterpriseName')
        search_EQ_orgInstCode = self.file_data.get('search_EQ_orgInstCode')
        search_EQ_queryFormat = self.file_data.get('search_EQ_queryFormat')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_signCode = self.file_data.get('search_EQ_signCode')
        search_EQ_uniformSocialCredCode = self.file_data.get('search_EQ_uniformSocialCredCode')
        search_EQ_operator = self.file_data.get('search_EQ_operator')
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_GTE_LTE_operTime_DATE_RANGE = self.file_data.get('search_GTE_LTE_operTime_DATE_RANGE')
        search_EQ_archiveViewStatus = self.file_data.get('search_EQ_archiveViewStatus')
        ret = EntAsynCheckRequest.get_page(curPage,maxSize,
                                            search_EQ_enterpriseName,
                                            search_EQ_orgInstCode,
                                            search_EQ_queryFormat,
                                            search_EQ_signCode,
                                            search_EQ_uniformSocialCredCode,
                                            search_EQ_qryReason,
                                            search_EQ_status,
                                            search_EQ_operator,
                                            search_EQ_operOrg,
                                            search_GTE_LTE_operTime_DATE_RANGE,
                                            search_EQ_archiveViewStatus,
                                            self.cookie)
        Log.info(ret)
        Log.info(ret.list[0].id)
        Log.info(ret.list[0].archiveId)
        self.assertIsNotNone(ret.list)
        return ret.list

    def select_archive(self):
        data = self.get_page()[0]
        id = data.id
        ret = EntAsynCheckRequest.ent_select_archive(id,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        return data


    def test_check1_pass(self):
        '''企业异步请求通过'''
        data = self.select_archive()
        archiveType = self.file_data.get('archiveType')
        creator = self.file_data.get('creator')
        dsRegiNo = data.dsRegiNo
        frgCorpNo = data.frgCorpNo
        expireDate = datetime.date.today()
        enterpriseName = data.enterpriseName
        ext1 = data.ext1
        ext2 = data.ext2
        ext3 = data.ext3
        ext4 = data.ext4
        ext5 = data.ext5
        ext6 = data.ext6
        extendDate = self.file_data.get('extendDate')
        id = data.archiveId
        note = data.note
        gsRegiNo = data.gsRegiNo
        oentTime = data.oentTime
        creatTime = oentTime
        orgCreditCode = data.orgCreditCode
        operTime = self.file_data.get('operTime')
        operationIdentifier = self.file_data.get('operationIdentifier')
        quantity = self.file_data.get('quantity')
        queryNum = self.file_data.get('queryNum')
        remarks = data.remarks
        reqId = data.reqId
        resCode = data.resCode
        resMsg = data.resMsg
        regiTypeCode = data.regiTypeCode
        orgInstCode = data.orgInstCode
        signCode = data.signCode
        uniformSocialCredCode = data.uniformSocialCredCode
        operOrg = data.operOrg
        ownOrg = data.ownOrg
        operator = data.operator
        serialNumber = data.serialNumber
        startDate = datetime.date.today()
        status = self.file_data.get('status1')
        ids = data.id
        ret = EntAsynCheckRequest.ent_pass(archiveType,enterpriseName,creatTime,creator,dsRegiNo,frgCorpNo,gsRegiNo,
                    expireDate,ext1,ext2,ext3,ext4,ext5,ext6,extendDate,id,note,orgCreditCode,
                    operTime,operationIdentifier,operator,operOrg,ownOrg,quantity,orgInstCode,
                    queryNum,remarks,reqId,resCode,resMsg,serialNumber,startDate,regiTypeCode,
                    signCode,uniformSocialCredCode,status,ids,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)

    def test_check2_pass(self):
        '''企业异步请求通过'''
        data = self.select_archive()
        archiveType = self.file_data.get('archiveType')
        creator = self.file_data.get('creator')
        dsRegiNo = data.dsRegiNo
        frgCorpNo = data.frgCorpNo
        expireDate = datetime.date.today()
        enterpriseName = data.enterpriseName
        ext1 = data.ext1
        ext2 = data.ext2
        ext3 = data.ext3
        ext4 = data.ext4
        ext5 = data.ext5
        ext6 = data.ext6
        extendDate = self.file_data.get('extendDate')
        id = data.archiveId
        note = data.note
        gsRegiNo = data.gsRegiNo
        oentTime = data.oentTime
        creatTime = oentTime
        orgCreditCode = data.orgCreditCode
        operTime = self.file_data.get('operTime')
        operationIdentifier = self.file_data.get('operationIdentifier')
        quantity = self.file_data.get('quantity')
        queryNum = self.file_data.get('queryNum')
        remarks = data.remarks
        reqId = data.reqId
        resCode = data.resCode
        resMsg = data.resMsg
        regiTypeCode = data.regiTypeCode
        orgInstCode = data.orgInstCode
        signCode = data.signCode
        uniformSocialCredCode = data.uniformSocialCredCode
        operOrg = data.operOrg
        ownOrg = data.ownOrg
        operator = data.operator
        serialNumber = data.serialNumber
        startDate = datetime.date.today()
        status = self.file_data.get('status1')
        ids = data.id
        ret = EntAsynCheckRequest.ent_pass(archiveType,enterpriseName,creatTime,creator,dsRegiNo,frgCorpNo,gsRegiNo,
                    expireDate,ext1,ext2,ext3,ext4,ext5,ext6,extendDate,id,note,orgCreditCode,
                    operTime,operationIdentifier,operator,operOrg,ownOrg,quantity,orgInstCode,
                    queryNum,remarks,reqId,resCode,resMsg,serialNumber,startDate,regiTypeCode,
                    signCode,uniformSocialCredCode,status,ids,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)

    def test_check2_refuse(self):
        '''企业异步审批拒绝'''
        id = self.get_page()[0].id
        refuseReasons = self.file_data.get('refuseReasons')
        ret = EntAsynCheckRequest.ent_check_refuse(id,refuseReasons,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)

    def test_check3_back(self):
        '''企业任务退回'''
        data = self.get_page()[0]
        archiveId = data.archiveId
        archiveViewStatus = data.archiveViewStatus
        assocbsnssData = data.assocbsnssData
        checkinfoId = data.checkinfoId
        clientIp = data.clientIp
        enterpriseName = data.enterpriseName
        creditUser = data.creditUser
        ext1 = data.ext1
        ext2 = data.ext2
        ext3 = data.ext3
        ext4 = data.ext4
        ext5 = data.ext5
        ext6 = data.ext6
        id = data.id
        note = data.note
        operOrg = self.file_data.get('operOrg')
        operTime = data.operTime
        operator = data.operator
        president = data.president
        qryReason = self.file_data.get('qryReason')
        queryFormat = self.file_data.get('queryFormat')
        queryTime = data.queryTime
        queryType = self.file_data.get('queryType')
        reason = data.reason
        refuseReasons = data.refuseReasons
        rekOrg = self.file_data.get('rekOrg')
        rekTime = data.rekTime
        rekType = data.rekType
        rekUser = self.file_data.get('rekUser')
        remarks = data.remarks
        reqId = data.reqId
        resCode = data.resCode
        resMsg = data.resMsg
        resultStatus = data.resultStatus
        resultType = data.resultType
        serialNumber = data.serialNumber
        source = data.source
        uniformSocialCredCode = data.uniformSocialCredCode
        signCode = data.signCode
        regiTypeCode = data.regiTypeCode
        orgInstCode = data.orgInstCode
        orgCreditCode = data.orgCreditCode
        gsRegiNo = data.gsRegiNo
        dsRegiNo = data.dsRegiNo
        frgCorpNo = data.frgCorpNo
        status = self.file_data.get('status')
        ret = EntAsynCheckRequest.ent_check_back(archiveId,
                    archiveViewStatus,
                    assocbsnssData,
                    checkinfoId,clientIp,
                    enterpriseName,creditUser,
                    ext1,ext2,ext3,
                    ext4,ext5,ext6,
                    id,note,operOrg,
                    operTime,operator,
                    president,qryReason,
                    queryFormat,queryTime,
                    queryType,reason,uniformSocialCredCode,
                    refuseReasons,rekOrg,
                    rekTime,rekType,signCode,
                    rekUser,remarks,regiTypeCode,
                    reqId,resCode,orgInstCode,
                    resMsg,resultStatus,orgCreditCode,
                    resultType,serialNumber,gsRegiNo,
                    source,status,dsRegiNo,frgCorpNo,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)









if __name__ == "__main__":
    pass